package com.peng.controller;

import com.github.pagehelper.PageInfo;
import com.peng.Repo.PageStatic;
import com.peng.pojo.OpenCourse;
import com.peng.service.OpenCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OpenCourseController {
    @Autowired
    private OpenCourseService openCourseService;

    @GetMapping("/home/getCourId")
    public List<OpenCourse> toget(@RequestParam("teacherId") Integer... teacherId) {
        return openCourseService.selectOpenCourseIdByTeacherId(teacherId);
    }

    @GetMapping("/home/get")
    public boolean get(Integer... id) {
        return openCourseService.deleteOpenCourse(id);
    }

    @GetMapping("/admin/getAllOpenCourse")
    public PageInfo<OpenCourse> getAllOpenCourse(@Nullable @RequestParam(name = "name") String name,
                                                 @Nullable @RequestParam(name = "teacherId") Integer teacherId,
                                                 @Nullable @RequestParam(name = "typeId") Integer typeId,
                                                 @RequestParam(name = "page", defaultValue = PageStatic.page) int page,
                                                 @RequestParam(name = "size", defaultValue = PageStatic.size) int size) {
        return openCourseService.selectAllOpenCourse(name, teacherId, typeId, page, size);
    }

    @GetMapping("/admin/updateOpenCourseStatus")
    public boolean updateOpenCourseStatus(@RequestParam(name = "status", defaultValue = "1") int status,
                                          @RequestParam(name = "id") @Nullable Integer... id) {
        return openCourseService.updateOpenCourseStatusById(status, id);
    }

    @GetMapping("/home/getOpenCourseClassTimeDesc")
    public List<OpenCourse> getOpenCourseClassTimeDesc() {
        return openCourseService.selectOpenCourseClassTimeDesc();
    }
}
